function comment_submit(oform) {
	var check_validate_code_response = function(oXML) {
		if(oXML == 'ok') {
			var comment_response = function(oXML) {
				if(oXML == 'ok') {
					// 评论成功
					oform.elements['nickname'].value = '';
					oform.elements['anonymous'].checked = false;
					oform.elements['comment_content'].value = '';
					$('#validate_img').click();
					//reload_validate_code($('#validate_img'), 70, 21);
					$('#validate_code').attr({ value: ''});
					alert('评论成功');
					comment_list(commentliparam)
				} else {
				}
			}
			var nickname = oform.elements['nickname'].value;
			var anonymous = oform.elements['anonymous'].checked;
			var comment_content = oform.elements['comment_content'].value;
			var aid = oform.elements['aid'].value;

			if(!anonymous && nickname == '') {
				alert('请输入您的昵称！');
				oform.elements['nickname'].focus();
				return false;
			}

			if(comment_content == '') {
				alert('评论不能为空！');
				oform.elements['comment_content'].focus();
				return false;
			}
			param = '&aid=' + aid;
			if(anonymous) param += '&anonymous=' + 1;
			param += '&nickname=' + nickname + '&comment_content=' + comment_content;
			url = commenturl + '?action=add';
			$.post(url, param, comment_response);
		} else {
			//reload_validate_code($('#validate_img'));
			alert('验证码错误！');
			$('#validate_img').click();
			$('#validate_code').attr({ value: ''});
		}
	}
	code = oform.elements['validate_code'].value;
	url = commenturl + '?action=query&code=' + code + '&front=1';
	var param = '';
	$.post(url, param, check_validate_code_response);
	return false;
}
function comment_list(param) {
	var comment_list_response = function(oXML) {
		$("#comment_html").html(oXML);
	}
	url = commenturl + '?' + param;
	$.post(url, param, comment_list_response);
}
function comment_up(id) {
	var comment_up_response = function(oXML) {
		if(oXML == 'ok') {
			var up = parseInt($("#comment_up_" + id).html());
			$("#comment_up_" + id).html(up+1);
		}
	}
	param = '';
	url = commenturl + '?action=up&id=' + id;
	$.post(url, param, comment_up_response);
}
function comment_down(id) {
	var comment_down_response = function(oXML) {
		if(oXML == 'ok') {
			var down = parseInt($("#comment_down_" + id).html());
			$("#comment_down_" + id).html(down+1);
		}
	}
	param = '';
	url = commenturl + '?action=down&id=' + id;
	$.post(url, param, comment_down_response);
}


function trimspace(str) {
	regExp1 = /^\s*/;
	regExp2 = /\s*$/;
	return str.replace(regExp1,'').replace(regExp2,'');
}
function ltrimspace(str) {
	regExp1 = /^\s*/;
	return str.replace(regExp1,'');
}
function rtrimspace(str) {
	regExp1 = /\s*$/;
	return str.replace(regExp1,'');
}
function comment_reply(id) {
	var replydata = $("#comment_reply_" + id).html();
	eval('comment_reply_flag_'+id+'=1');
	$("#comment_reply_" + id).attr("style","display:_blank");


	// 去掉前后的空格，回车
	// 替换<P>
	replydata = replydata.replace('&nbsp;', ' ');
	replydata = replydata.replace('<P>', '');
	replydata = replydata.replace('</P>', '\n');
	replydata = trimspace(replydata);
	replyform = '<TEXTAREA NAME="comment_reply_text_'+id+'" ID="comment_reply_text_'+id+'" ROWS="5" COLS="20" class="formarea" style="width:90%">' + replydata + '</TEXTAREA><INPUT TYPE="button" value="回复" onclick="comment_reply_submit('+id+');"><INPUT TYPE="button" value="取消" onclick="comment_reply_cancel('+id+');">';
	$("#comment_reply_" + id).html(replyform);
}
function comment_reply_cancel(id) {
	//eval('comment_reply_flag_'+id+'=0');
	var replydata = $("#comment_reply_text_" + id).text();
	if(replydata == '') {
		$("#comment_reply_" + id).attr("style","display:none");
	} else {
		replydata = replydata.replace(' ', '&nbsp;');
		replydata = trimspace(replydata);
		// 去掉最后的回车 
		replydata = replydata.replace("/\n/", '</P><P>');
		replydata = '<P>'+replydata+'</P>';
		//alert(replydata);
	}
	replydata = trimspace(replydata);
	$("#comment_reply_" + id).html(replydata);
}
function comment_reply_submit(id) {
	var comment_reply_submit_response = function(oXML) {
		if(oXML == 'ok') {
			$("#comment_reply_" + id).html(replydata);
		}
	}
	var replydata = $("#comment_reply_text_" + id).text();
	param = 'reply=' + replydata;
	url = commenturl + '?action=reply&id=' + id;
	$.post(url, param, comment_reply_submit_response);
}
